package main

// 管道默认是双向的
func main() {
	// 创建一个cahnnel ， 双向的
	ch := make(chan int)

	// 双向channel能隐式转换为单向channel
	var writeCh chan<- int = ch // 只能写不能读
	var readCh <-chan int = ch  // 只能读不能写

	// 写
	writeCh <- 666
	/*
		读报错
		Invalid operation: <- writeCh (receive from send-only type chan<- int)
		<- writeCh
	*/

	// 读
	<-readCh
	/* 写报错
	Invalid operation: readCh <- 888 (send to receive-only type <-chan int)
	readCh <- 888
	*/

	// 单向无法转为双向
	//var ch2 <- chan int = writeCh
	//var ch3 chan <- int  = readCh

}
